package me.zhengjie.modules.houseshowconfig.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.modules.houseshowconfig.domain.HouseShowConfig;
import me.zhengjie.modules.houseshowconfig.service.HouseShowConfigService;
import me.zhengjie.modules.houseshowconfig.service.dto.HouseShowConfigDto;
import me.zhengjie.modules.houseshowconfig.service.dto.HouseShowConfigQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author TianI
* @date 2021-12-24
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "HouseShowConfig管理")
@RequestMapping("/api/houseShowConfig")
public class HouseShowConfigController {

    private final HouseShowConfigService houseShowConfigService;

    @GetMapping
    @Log("查询HouseShowConfig")
    @ApiOperation("查询HouseShowConfig")
    @PreAuthorize("@el.check('houseShowConfig:list')")
    public ResponseEntity query(HouseShowConfigQueryParam query, Pageable pageable){
        return new ResponseEntity<>(houseShowConfigService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增HouseShowConfig")
    @ApiOperation("新增HouseShowConfig")
    @PreAuthorize("@el.check('houseShowConfig:add')")
    public ResponseEntity create(@Validated @RequestBody HouseShowConfigDto resources){
        return new ResponseEntity<>(houseShowConfigService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改HouseShowConfig")
    @ApiOperation("修改HouseShowConfig")
    @PreAuthorize("@el.check('houseShowConfig:edit')")
    public ResponseEntity update(@Validated @RequestBody HouseShowConfigDto resources){
        houseShowConfigService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除HouseShowConfig")
    @ApiOperation("删除HouseShowConfig")
    @PreAuthorize("@el.check('houseShowConfig:del')")
    public ResponseEntity delete(@RequestBody Set<Long> ids) {
        houseShowConfigService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出HouseShowConfig")
    @ApiOperation("导出HouseShowConfig")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('houseShowConfig:list')")
    public void download(HttpServletResponse response, HouseShowConfigQueryParam query) throws IOException {
        houseShowConfigService.download(houseShowConfigService.queryAll(query), response);
    }*/

}
